package com.dingmouren.smaple.paletteimageview;

import com.dingmouren.paletteimageview.util.ColorUtil;
import ohos.agp.utils.Color;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

public class ColorTest {

    int alpha = 50;
    int red = 50;
    int green = 50;
    int blue = 50;

    int colorValue;

    @Before
    public void initColor() {
        colorValue = Color.argb(alpha, red, green, blue);
    }

    @Test
    public void color2HlsTest() {
        int color = Color.getIntColor("#00b050");
        float[] hls = new float[3];
        ColorUtil.color2HSL(color, hls);
        Assert.assertEquals(color, ColorUtil.HSL2Color(hls));
    }

    @Test
    public void hls2ColorTest() {
        float[] hls = new float[]{0f, 0f, 0.86f};
        int color = ColorUtil.HSL2Color(hls);
        Assert.assertEquals(color, Color.rgb(219, 219, 219));
    }

    @Test
    public void colorArgbTest() {
        Assert.assertEquals(colorValue, ColorUtil.argb(alpha, red, green, blue));
    }

    @Test
    public void colorRgbTest() {
        int argColor = Color.rgb(red, green, blue);
        Assert.assertEquals(argColor, ColorUtil.rgb(red, green, blue));
    }

    @Test
    public void colorValueTest() {
        Assert.assertEquals(colorValue, ColorUtil.argb(alpha, red, green, blue));
    }

    @Test
    public void parseAlphaValueTest() {
        Assert.assertEquals(alpha, ColorUtil.alpha(colorValue));
    }

    @Test
    public void parseRedValueTest() {
        Assert.assertEquals(red, ColorUtil.red(colorValue));
    }

    @Test
    public void parseGreenValueTest() {
        Assert.assertEquals(green, ColorUtil.green(colorValue));
    }

    @Test
    public void parseBlueValueTest() {
        Assert.assertEquals(blue, ColorUtil.blue(colorValue));
    }
}
